package com.sailing.xjpb.common.tree;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * VUE前端需要的树形结构控件的数据结构
 *
 * @author YW
 * create 2020/4/28
 */
@SuppressWarnings("unchecked")
public class SailingVueTree extends HashMap<String, Object> implements SailingTree<SailingVueTree> {
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    /**
     * 树节点ID
     */
    private static final String TREE_ID = "treeId";
    /**
     * 父级ID
     */
    private static final String PARENT_ID = "parentId";
    /**
     * 子节点
     */
    private static final String CHILDREN = "children";
    /**
     * 树节点代码
     */
    private static final String TREE_CODE = "treeCode";
    /**
     * 树节点名称
     */
    private static final String TREE_NAME = "treeName";
    /**
     * 树节点类型
     */
    private static final String TYPE = "type";
    /**
     * 是否是叶子节点
     */
    private static final String LEAF = "leaf";

    public SailingVueTree() {
        this.setTreeId(null);
        this.setParentId(null);
        this.setTreeCode(null);
        this.setTreeName(null);
        this.setChildren(new ArrayList<>());
        this.setLeaf(false);
        this.setType(null);
    }

    /**
     * 新增属性信息
     *
     * @param key   key
     * @param value 值
     */
    public void addProperty(String key, Object value) {
        this.put(key, value);
    }

    public void addChildren(List<SailingVueTree> childrenNodes) {
        if (childrenNodes == null || childrenNodes.isEmpty()) {
            return;
        }
        List<SailingVueTree> children = this.getChildren();
        children.addAll(childrenNodes);
        this.setChildren(children);
    }

    @Override
    public String getTreeId() {
        return (String) get(TREE_ID);
    }

    public void setTreeId(String treeId) {
        this.put(TREE_ID, treeId);
    }

    @Override
    public String getParentId() {
        return (String) get(PARENT_ID);
    }

    public void setParentId(String parentId) {
        this.put(PARENT_ID, parentId);
    }

    @Override
    public List<SailingVueTree> getChildren() {
        return (List<SailingVueTree>) this.get(CHILDREN);
    }

    @Override
    public void setChildren(List<SailingVueTree> children) {
        if (children == null || children.isEmpty()) {
            this.put(LEAF, Boolean.TRUE);
        } else {
            this.put(LEAF, Boolean.FALSE);
        }
        this.put(CHILDREN, children);
    }

    public String getTreeCode() {
        return (String) get(TREE_CODE);
    }

    public void setTreeCode(String treeCode) {
        this.put(TREE_CODE, treeCode);
    }

    public String getTreeName() {
        return (String) get(TREE_NAME);
    }

    public void setTreeName(String treeName) {
        this.put(TREE_NAME, treeName);
    }

    public Boolean getLeaf() {
        return (Boolean) get(LEAF);
    }

    public void setLeaf(Boolean leaf) {
        this.put(LEAF, leaf);
    }

    public String getType() {
        return (String) get(TYPE);
    }

    public void setType(String type) {
        this.put(TYPE, type);
    }

}
